/*
 * key_hal.h
 *
 *  Created on: Sep 14, 2013
 *      Author: Ken Arok
 */

#include "config_board.h"

#if BOARD_2_1_USED

#ifndef KEY_HAL_H_
#define KEY_HAL_H_

#include "compiler.h"

/* Keyword definition
   MSB [SC4 SC3 SC2 SC1 * 7 4 1 0 8 5 2 # 9 6 3] LSB
   0 -> pressed
   1 -> released
 */
#define KEYWORD_SHORTCUT4		0x7FFF
#define KEYWORD_SHORTCUT3		0xBFFF
#define KEYWORD_SHORTCUT2		0xDFFF
#define KEYWORD_SHORTCUT1		0xEFFF
#define KEYWORD_ASTERIC			0xFFF7
#define KEYWORD_NUMBER7			0xFFFB
#define KEYWORD_NUMBER4			0xFFFD
#define KEYWORD_NUMBER1			0xFFFE
#define KEYWORD_NUMBER0			0xFF7F
#define KEYWORD_NUMBER8			0xFFBF
#define KEYWORD_NUMBER5			0xFFDF
#define KEYWORD_NUMBER2			0xFFEF
#define KEYWORD_CROSS			0xF7FF
#define KEYWORD_NUMBER9			0xFBFF
#define KEYWORD_NUMBER6			0xFDFF
#define KEYWORD_NUMBER3			0xFEFF
#define KEYWORD_NONE			0xFFFF


#define KEYWORD_COMBINE1		0xF111		//! * and 5 and 9
#define KEYWORD_COMBINE2		0xF222		//! 7 and 0 and 3
#define KEYWORD_COMBINE3		0xFAAA		//! 7 and 2 and 3
#define KEYWORD_COMBINE4		0xF1F1		//! * and 7 and 6
#define KEYWORD_COMBINE5		0xF4F4		//! * and 4 and 3
#define KEYWORD_COMBINE11		0xFEFE		//! 1 and 3
#define KEYWORD_COMBINE12		0xFAAF		//! 2 and 9
#define KEYWORD_COMBINE13		0xF99F		//! 6 and 8
#define KEYWORD_COMBINE14		0xFFAA		//! 1 and 8
#define KEYWORD_COMBINE15		0xF9F9		//! 6 and 7


/** \brief Initialize keypad interface.
 */
extern void key_init(void);

/** \brief Get 16 bit key pressed representation.
 *
 * \return KEYWORD		16 bit key representative of pressed button.
 *
 */
extern uint16_t key_get_word(void);

/** \brief Get character of key pressed representation.
 *
 * \return KEYCHAR		Character of key pressed representation.
 *
 */
extern char key_get_char(void);

/** \brief Get 16 bit of key pressed representation for combination key.
 *
 * \return KEYCOMBINE		16 bit of key pressed representation.
 *
 */
extern uint16_t key_get_combine(void);

/** \brief Wait until one of the wanted characters of keypad is pressed.
 *
 * \param	_keychar		Pointer to the string of waited characters.
 *
 * \return Status
 *	\retval 0			Failed
 *	\retval Keychar		Character of pressed key.
 *
 */
extern char key_wait_keychar(const char *_keychar);

/** \brief Wait the keypad until it is released.
 */
extern void key_wait_release(void);


#endif /* KEY_HAL_H_ */

#endif /* BOARD_2_1_USED */
